<?php

class CheckoutView extends View {

	protected $orders;
	protected $userInfo;
	
	function __construct() {
		
	}
	
	function getOrders() {
		return $this->orders;
	}
	
	function setOrders($o) {
		$this->orders = $o;
	}
	
	function getUserInfo() {
		return $this->userInfo();
	}
	
	function setUserInfo($u) {
		$this->userInfo = $u;
	}
	
	function display() {
		echo '<div style="display:block;">';
		
		if ($this->orders) {
			echo '<div style="width:90%">';
			echo '<h3 style="margin-bottom:10px">Shopping Cart</h3>';
			echo '<table class="table table-striped">';
			echo '<thead><th>id</th><th>title</th><th>price</th><th>copies</th></thead>';
			
			//how much to charge
			$sumPrice = 0;
			$orderLines = explode('[]', $this->orders);
			for ($i=0 ; $i<sizeof($orderLines) ; $i++) {
				$tokens = explode('_', $orderLines[$i]);
				$movieId = $tokens[0];
				$movieTitle = $tokens[1];
				$price = $tokens[2];
				$copies = $tokens[3];
				$sumPrice = $sumPrice + $price;
				echo '<tr><td>'.$movieId.'</td><td>'.$movieTitle.'</td><td>'.$price.'</td><td>'.$copies.'</td></tr>';
			}
			echo '</table>';
			echo '</div>';
		}
		else {
			echo '<p>No movies have been added to the shopping cart</p>';
		}
		
		echo '<form action="?page=buy&view=checkout" method="POST">';
		echo '<input type="hidden" name="orders" value="'.$this->orders.'" />';
		
		echo '<input type="hidden" name="action" value="save" />';
		echo '<input type="hidden" name="memberId" value="'.$this->userInfo->getId().'" />';
		
		
		echo '<table>';
		echo '<tr><td>Shipping:</td><td><input type="text" name="shipping" value="'.$this->userInfo->getAddress().'" /></td></tr>';
		echo '<tr><td>Credit Type:</td><td><input type="text" name="creditType" value="'.$this->userInfo->getCreditType().'" /></td></tr>';
		echo '<tr><td>Credit Number:</td><td><input type="text" name="creditNumber" value="'.$this->userInfo->getCreditNumber().'" /></td></tr>';
		echo '<tr><td>Total Cost:</td><td>'.$sumPrice.'</td></tr>';
		echo '<tr><td></td><td></td></tr>';
		echo '<tr><td></td><td><input type="submit" value="Check-out" class="btn btn-default" /></td></tr>';
		echo '</table>';
		echo '</div>';
	}

}